var Mock = require('mockjs');
Mock.mock(/\/web\/orders/, function(options) {

	console.log(options, "mockjs");
	// 获取url问号的位置
	// url /web/orders?page=mumu&age=18&
	var po = options.url.indexOf('?');
	// 如果不为-1 就说明有条件
	if (po != -1) {
		// 获取到问号后面的数据
		var query = options.url.slice(po + 1);
		// 去掉最后一个&符号
		query = query.slice(0, -1);
		// 查询条件name=mumu&age=18 分割为数组
		// tempArr = ["name=mumu","age=18"]
		var tempArr = query.split('&');
		// 查询的最终对象
		query = {};
		// 数组遍历
		for (var i = 0; i < tempArr.length; i++) {
			// 数组的元素按等号再次分割
			// subarr = ["name","mumu"]
			var subarr = tempArr[i].split('=');
			//  query["name"] ="mumu"
			query[subarr[0]] = subarr[1]
		}
		console.log(query, "查询条件")

	}
	return Mock.mock({
		status: 0,
		"list2|10":[{
					"Id|+1":6000000,
					// 退款单号
					"Refundorders|313860000-314860000":1,
					//申请时间
					"Orderstime":'@datetime',
					//用户账号
					"Useraccount|13000000000-19000000000":1,
					// 退款金额
					"Refundamount|200-800.2":1,
					"Refundstatus": function() {
						// 如果有query.OrderStatus订单状态，直接返回
						if (query.Refundstatus && query.Refundstatus != 'all') {
							return query.Refundstatus;
						} else {
							var temp = ["Processed", "Havedealwith","Refused","Processeds"];
							// 随机0-temp的长度
							var n = Math.ceil(Math.random() * (temp.length));
							return temp[n];
						}
					},
					"Processingtime|1":"@datetime",
				}],

		"list|10": [{
			"Id|+1": 5000000,
			"OrderNum|720806005398000-720806005898000": 1,
			"ParentOrderID|500-999": 1,
			"CreateAt": '@datetime',
			"TotalAmount|200-800.2": 1,
			"CustomerTotalAmount|": function() {
				return this.TotalAmount * 0.8
			},
			"RefundedAmount|200-800.2": 1,
			"StoreId|1000-100000": 1,
			"OrderStatus": function() {
				// 如果有query.OrderStatus订单状态，直接返回
				if (query.OrderStatus && query.OrderStatus != 'all') {
					return query.OrderStatus;
				} else {
					var temp = ["Pending", "Processing", "wan", "Cancelled", "Accepted", "Sent", "Received", "Returned"];
					// 随机0-temp的长度
					var n = Math.ceil(Math.random() * temp.length);
					return temp[n];
				}
			},
			"DeliverStatus|1": ["Pending", "Accepted", "Sent", "Received", "Returned"],
			"ConfirmedAt": '@time',
			"Deleted|1": true,
			"CustomerId|5000-9999999": 1,
			"Consignee": '@cname',
			"Phone": /1\d{10}/,
			"ShippingAddress": "@county(true)",
			"PaymentStatus|1": ["Pending", "Authorized", "Paid", "PartiallyRefunded", "Refunded", "Voided"],
			"PaymentCode|5000-900000": 1,
			"PaymentMethod|1": ["支付宝", "微信", "网银", "QQ", "现金"],
			"TimeOfPayment": '@time',
			"PickupInStore|1": true,
			"Deliverytime": '@time',
			
			"date":"@date",
						"nickName":"奔跑的河马",
						"name":'@cname',
						"address":"老集老集2店",
						"role":"系统管理员,运营",
						"status|1-2":true
		}],
		person:{
					user:'qx123',
					pwd:'qx123456'
				},
		pagination: {
			"pageSize": 10,
			"pagerCount": 10,
			"total": 100,
			"currentPage": query.page ? query.page * 1 : 1
		},
		subTotal:{
			"all|99999-999999":1,
			"Pending|100-1000":1,
			"Accepted|100-1000":1,
			"Sent|100-1000":1,
			"wan|1000-2000":1,
			"Received|100-1000":1,
			"Returned|50-500":1,
			
		}

	})
})

Mock.mock("api/v1/data","get",function(req){
 return Mock.mock({
  "list|3":[
   {
    "ProductCode|1000000-9999999": 1,
    "Sku|6900000000-6900999999":1,
	"PictureUrl":"@dataImage('50x50','Hello')",
    "ProductName":'@ctitle(5)',
    "price|80-150":1,
    "PromotionPrice|70.2":1,
    "FeeRate|1-50": 1,
    "LimitCount|5-9": 1,
    "PromotionStock|900-1000":1,
   }
  ],
 
  
 })
})
